home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
byt86aug.arc
/
LETS.SRC
< prev
next >
Wrap
Text File
|
1980-01-01
|
6KB
|
275 lines
/* ==== Byte Benchmark: Eratosthenes Sieve
02-22-86 WGW ==== */
#define ITERATIONS 10 /* number of times to
perform test */
#define LOCAL 1 /* use stack for flags */
#define GLOBAL 0 /* use global area for flags */
typedef char flag ; /* different types make a
difference */
#include <stdio.h> /* standard I/O definitions */
/* ---- Main Function ---- */
#define SIZE 7000
#if GLOBAL
flag flags [ SIZE + 1 ] ; /* prime number flag array */
#endif
main ()
{
/* ---- Variable definitions ---- */
/* */
/* Note: only some register specifications will
be used due to the */
/* limited number of registers available.
Normally, the first */
/* items are allocated to registers. */
register int i ; /* ordered by preference */
register int k ;
register int prime ;
register int count ;
register int iterations ;
#if LOCAL
flag flags [ SIZE + 1 ] ;
/* prime number flag array */
#endif
/* ---- Show off start of execution ---- */
printf ( "Starting Eratosthenes Sieve
Benchmark\n\n" ) ;
printf ( "%d iterations.\n\n", ITERATIONS ) ;
for ( iterations = ITERATIONS ; iterations ; --
iterations )
{
/* ---- Initialize Sieve Flag Array ---- */
for ( i = 0 ; i < SIZE ; ++ i )
flags [ i ] = 1 ; /* mark all as prime numbers */
/* ---- Search for Prime Numbers ---- */
for ( i = 0 /* scan for next prime number */
, count = 0 /* keep count of primes found */
; i < SIZE
; ++ i
)
if ( flags [ i ] != 0 ) /* check if prime found */
{
/* ---- Prime found. Count it and unmark
multiples ---- */
++ count ; /* increment number of primes */
for ( prime = i + i + 3
/* mark multiples as non-prime */
, k = i + prime
/* start with first multiple */
; k < SIZE
; k += prime
)
flags [ k ] = 0 ;
/* reset multiples to non-prime */
}
}
/* ---- Mark end of execution ---- */
printf ( "%d prime numbers found.\n", count ) ;
printf ( "End of Test\n\n" ) ;
}
/* ==== End of Eratosthenes Sieve Benchmark ==== */
.pa
/* ==== Byte Benchmark: Calculation Test 02-22-86 WGW ==== */
#include <stdio.h> /* standard I/O definitions */
/* ==== Main Function ==== */
#define ITERATIONS 5000
main ()
{
float a, b, c ;
int i ;
/* ---- Show start of test ---- */
printf ( "Start of Calculation Test.\n\n" ) ;
/* ---- Perform test loop ---- */
for ( i = ITERATIONS /* setup for timing loop */
, a = 2.71828
, b = 3.14159
, c = 1
; i /* exit when end of test */
; -- i
)
{
/* ---- Perform balanced set of calculations ---- */
c *= a ; /* same as c = c * a */
c *= b ;
c /= a ; /* same as c = c / a */
c /= b ;
}
/* ---- Show end of test ---- */
printf ( "End of test. Accumulated error:
%f\n\n", c - 1 ) ;
}
/* ==== End of Eratosthenes Sieve Benchmark ==== */
.pa
/* ==== Byte Benchmark: Write 64 kbyte file
02-22-86 WGW ==== */
#include <stdio.h> /* standard I/O definitions */
/* ==== Main Test Function ==== */
#define RECORDS 512 /* records in test file */
#define REC_SIZE 128 /* size of records,
total is 64kbyes */
main ()
{
int file ;
int records ;
char buffer [ REC_SIZE ] ;
int i ; /* buffer fill index */
static char file_name [] = "B:TEST" ;
/* ---- Show start of test ---- */
printf ( "Writing TEST file.\n\n" ) ;
/* ---- Fill output buffer with recognizable
information ---- */
for ( i = 0 ; i < sizeof ( buffer ) ; ++ i )
buffer [ i ] = i ;
/* ---- Write information ---- */
if (( file = creat ( file_name, 0 )) > -1 )
{
/* ---- File opened, try writing all the records ---- */
for ( records = RECORDS ; records ; -- records )
if ( write ( file, buffer, sizeof ( buffer )) !=
sizeof ( buffer ))
{
printf ( "Write error.\n" ) ; /* show error */
break ; /* exit from loop */
}
/* ---- Close down the file ---- */
close ( file ) ;
}
else
printf ( "Cannot open %s\n", file_name ) ;
/* ---- Show end of test ---- */
printf ( "End of Write Test.\n\n" ) ;
}
/* ==== End of Write 64 kbyte File Benchmark ==== */
.pa
/* ==== Byte Benchmark: Read 64 kbyte file
02-22-86 WGW ==== */
#include <stdio.h> /* standard I/O definitions */
/* ==== Main Test Function ==== */
#define RECORDS 512 /* records in test file */
#define REC_SIZE 128 /* size of records,
total is 64kbyes */
main ()
{
int file ;
int records ;
char buffer [ REC_SIZE ] ;
static char file_name [] = "B:TEST" ;
/* ---- Show start of test ---- */
printf ( "Reading TEST file.\n\n" ) ;
/* ---- Read information ---- */
if (( file = open ( file_name, 0 )) > -1 )
{
/* ---- File opened, try reading all the records ---- */
for ( records = RECORDS ; records ; -- records )
if ( read ( file, buffer, sizeof ( buffer )) !=
sizeof ( buffer ))
{
printf ( "Read error.\n" ) ;/* show error */
break ; /* exit from loop */
}
/* ---- Close down the file ---- */
close ( file ) ;
}
else
printf ( "Cannot open %s\n", file_name ) ;
/* ---- Show end of test ---- */
printf ( "End of Read Test.\n\n" ) ;
}
/* ==== End of Read 64 kbyte File Benchmark ==== */